package CSS::Parser;
use Moose;

has 'parser'    => ( isa => 'Any' , is => 'rw' , default => 'CSS::Parser::AsBuilder' );

sub read_file {
    my ($self , $file) = @_;
    
    if (-e $file) {
	local *IN;
 	open(IN, $file) or die "couldn't open file: $!";
	my $source = join '',<IN>;
	close(IN);
	return $self->parse_string($source) if $source;
    }
}

sub read_string {
    my ($self , $string) = @_;
      
    return $self->parse_string($string) if length $string;
}

sub parse_string {
    my ($self , $string) = @_;
    
    use CSS::Parser::AsBuilder;
    my $parser = $self->parser->new;
    
    # return CSS::Builder Object
    return $parser->parse_string($string);
}

1;